package com.gmrz.uaf.crypto;

public class CryptoConstants {
    public static final String BOUNCY_CASTLE_PROVIDER_NAME = "BC";
    public static final String SIGNATURE_SERVICE_NAME = "Signature";
    public static final String DEFAULT_EXTERNAL_ENCRYPTION_KEY_ALGO = "AES";
    public static final String DEFAULT_EXTERNAL_HMAC_KEY_ALGO = "HmacSHA256";
    public static final int MINIMUM_EXTERNAL_ENCRYPTION_KEY_LENGTH = 16;
    public static final int MINIMUM_EXTERNAL_HMAC_KEY_LENGTH = 32;
    public static final String DEFAULT_EXTERNAL_ENCRYPTION_KEY_TRANSFORMATION = "AES/GCM/NoPadding";
    public static final String EC_CURVE_SECP256R1 = "secp256r1";
    public static final String EC_CURVE_SECP256K1 = "secp256k1";
    public static final int RSA_2048_MODULUS_LENGTH = 256;
    public static final int RSA_2048_RAW_SIGNATURE_LENGTH = 256;
    public static final int ECDSA_SIGNATURE_FIELD_SIZE = 32;

    public enum UAFAlgkey {
        // 这个是代表的算法的不同格式
        UAF_ALG_KEY_ECC_X962_RAW(256, "ecc-x962-raw", "EC"),
        UAF_ALG_KEY_ECC_X962_DER(257, "ecc-x962-der", "EC"),
        UAF_ALG_KEY_RSA_2048_PSS_RAW(258, "rsa-2048-pss-raw", "RSA"),
        UAF_ALG_KEY_RSA_2048_PSS_DER(259, "rsa-2048-pss-der", "RSA");

        private int format;
        private String name;
        private String keyAlgo;

        public int getFormat() {
            return this.format;
        }

        public String getName() {
            return this.name;
        }

        public String getKeyAlgo() {
            return this.keyAlgo;
        }

        UAFAlgkey(int t, String name, String keyAlgo) {
            this.format = t;
            this.name = name;
            this.keyAlgo = keyAlgo;
        }

        public static UAFAlgkey from(int keyFormat) {
            for (UAFAlgkey k : values()) {
                if (k.format == keyFormat)
                    return k;
            }
            return null;
        }
    }

    public enum UAFAlgSign {
        UAF_ALG_SIGN_SECP256R1_ECDSA_SHA256_RAW(1, "ecdsa-secp256r1-sha256-raw", "SHA256WITHECDSA", "SHA-256"),
        UAF_ALG_SIGN_SECP256R1_ECDSA_SHA256_DER(2, "ecdsa-secp256r1-sha256-der", "SHA256WITHECDSA", "SHA-256"),
        UAF_ALG_SIGN_RSASSA_PSS_SHA256_RAW(3, "rsassa-pss-sha256-raw", "SHA256WITHRSA/PSS", "SHA-256"),
        UAF_ALG_SIGN_RSASSA_PSS_SHA256_DER(4, "rsassa-pss-sha256-der", "SHA256WITHRSA/PSS", "SHA-256"),
        UAF_ALG_SIGN_SECP256K1_ECDSA_SHA256_RAW(5, "ecdsa-secp256k1-sha256-raw", "SHA256WITHECDSA", "SHA-256"),
        UAF_ALG_SIGN_SECP256K1_ECDSA_SHA256_DER(6, "ecdsa-secp256k1-sha256-der", "SHA256WITHECDSA", "SHA-256"),
        UAF_ALG_SIGN_SM2(7, "sm2-sm3", "SM2", "SM3"),
        UAF_ALG_SIGN_RSASSA_PKCS1_SHA256_RAW(8, "rsassa-pkcs1-sha256-raw", "SHA256WITHRSA", "SHA-256"),
        UAF_ALG_SIGN_RSASSA_PKCS1_SHA256_DER(9, "rsassa-pkcs1-sha256-der", "SHA256WITHRSA", "SHA-256"),
        UAF_ALG_SIGN_RSA(10, "rsa", "RSA", "SHA-256"),
        UAF_ALG_SIGN_SECP256R1_ECDSA_SHA512_DER(11, "ecdsa-sha512-der", "SHA512WITHECDSA", "SHA-512"),
        UAF_ALG_SIGN_RSASSA_PKCS1_SHA384_RAW(12, "rsassa-pkcs1-sha384-raw", "SHA384WITHRSA", "SHA-384"),
        UAF_ALG_SIGN_RSASSA_PKCS1_SHA512_RAW(13, "rsassa-pkcs1-sha512-raw", "SHA512WITHRSA", "SHA-512"),
        UAF_ALG_SIGN_RSASSA_PSS_SHA384_RAW(14, "rsassa-pss-sha384-raw", "SHA384WITHRSA/PSS", "SHA-384"),
        UAF_ALG_SIGN_RSASSA_PSS_SHA512_RAW(15, "rsassa-pss-sha512-raw", "SHA512WITHRSA/PSS", "SHA-512"),
        UAF_ALG_SIGN_RSASSA_PKCS1_SHA1_RAW(17, "rsassa-pkcs1-sha1-raw", "SHA1WITHRSA", "SHA-1"),
        UAF_ALG_SIGN_SECP256R1_ECDSA_SHA384_DER(18, "ecdsa-sha384-der", "SHA384WITHECDSA", "SHA-384");

        private int suite;
        private String name;
        private String signatureAlgo;
        private String hashingAlgo;

        public int getSuite() {
            return this.suite;
        }

        public String getName() {
            return this.name;
        }

        public String getHashingAlgo() {
            return this.hashingAlgo;
        }

        public String getSignatureAlgo() {
            return this.signatureAlgo;
        }

        UAFAlgSign(int t, String name, String signatureAlgo, String hashingAlgo) {
            this.suite = t;
            this.name = name;
            this.signatureAlgo = signatureAlgo;
            this.hashingAlgo = hashingAlgo;
        }

        public static UAFAlgSign from(int algoSuite) {
            for (UAFAlgSign t : values()) {
                if (t.suite == algoSuite)
                    return t;
            }
            return null;
        }
    }
}
